import Vue from 'vue';
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
    count:0,
    file:{},
    fileList:[]
}
const mutations = {
    increment(state,count){
        state.count = count;
    },
    decrement(state){
        state.count--
    },
    setFileList(state,task){
        state.file = task
        for(let i = 0;i < state.fileList.length;i++){
            if(task.name === state.fileList[i].name){
                state.fileList[i].complete = task.complete
                return false
            }
        }
        state.fileList.push(state.file)
    }
}

const getters = {
    getCount: state => state.count,
    getFileList: state => state.fileList
}


const actions = {
    // eslint-disable-next-line no-undef
    increment:({commit},count) =>commit('increment',count),
    decrement:({commit}) =>commit('decrement'),
    setFileList:({commit,task}) =>commit('setFileList',task)

}

export default new Vuex.Store({
    state,
    actions,
    mutations,
    getters
})
